package model;

import java.sql.Time;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JLabel;

import UI.Main;

public class LabelManager extends Thread implements Observer{

	private JLabel lbTime;
	private JLabel lbScore;
	private JLabel lbKills;
	private Player p;
	private int time;
	private Main main;
	
	public LabelManager(JLabel time, JLabel score, JLabel kills, Main m){
		lbTime = time;
		lbScore = score;
		lbKills = kills;
		main = m;
		//p = player;
	}
	
	public void setPlayer(Player p){
		this.p = p;
	}
	
	public void resetTimer(int seconds){
		time = seconds;
	}
	
	public void run(){
		try {
			while(time > 0){
				Thread.sleep(1000);
				time--;
				//System.out.println(time);
				lbTime.setText(""+time);
				//lbTime.repaint();
			
				lbScore.repaint();
				lbKills.repaint();
			}
			main.lose();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Override
	public void update(Observable arg0, Object arg1) {
		System.out.println("Player properties changed ...");
		try{
			int arg = (Integer)arg1;
			if(arg > 0){
				System.out.println("... it was the score("+arg+").");
				lbScore.setText(""+arg);
			} else{
				System.out.println("... it was the kills("+arg+").");
				arg *= -1;
				lbKills.setText(""+arg);
			}
		}catch(Exception e){
			
		}
	}
}
